<head>
    <meta name="_token" content="{{ csrf_token() }}"/>
</head>
<?php
use App\Http\Controllers\AutoAdviceController;
?>
@extends('app')

@section('otherResource')
    <style>
        a:hover {text-decoration: none;}
    </style>
@endsection


@section('rightPanel')
    <div class="row">
        <h1 class="page-header">建议查看</h1>
    </div>

    <!--
    <div class="row" style="position:relative" >
        <label style="float: left;width:8%; font-size: large">身份列表</label>
        <select id = "selecter" class="form-control" style="width: 15%;float: left;">
            <option value="-1">全部</option>
            <option value="1">系统管理员</option>
            <option value="2">医生，教练</option>

        </select>
    </div>
    -->
    <div id="adviceList">
    <?php
            foreach($advice as $a){
                echo "<div class=\"row col-md-9\">";
                $type = $a['type'];
                switch($type){
                    case "1":
                        echo "<p style='color:#060008' >";
                        echo "<img src='/Image/admin.png' style='width: 5%'>";
                        break;
                    case "2":
                        echo "<p style='color:#060008' >";
                        echo "<img src='/Image/doctor.png' style='width: 5%'>";
                        break;
                    default:
                }
                echo "&nbsp&nbsp&nbsp&nbsp".$a['adviser'].":   ".nl2br($a['content']."</p>");
                echo "<hr /> </div>";
            }
    ?>

    <?php /*$aa=new AutoAdviceController();
    	$as=$aa->getAdvicesForMe();
    	foreach($as as $a)
    	{
			echo "<div class=\"row col-md-9\">";
            echo "<p style='color:blue' >";
            echo "<img src='/Image/doctor.jpg' style='width: 10%'>";
    		echo "自动建议:   ".$a." </p>";
			echo "<hr /> </div>";
    	}*/
    ?>
    </div>
    <div class="row col-md-9">
        {!!$advice->render()!!}
    </div>
@endsection

@section('otherJs')
@endsection


<script src="{{asset("common/js/jquery-1.11.3.min.js")}}"></script>
<script src="common/js/bootstrap.min.js"></script>

<script>
    $(document).ready(function(){
        $('#selecter').change(function(){
            $.ajax({
                type:'POST',
                url:'/advice/ajax',
                data:{type: $('#selecter option:selected').val()},
                dataType:'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success:function(data){
                        console.log(data.advice);

                        var f = document.getElementById("adviceList");
                        var childs = f.childNodes;
                        for(var i = childs.length - 1; i >= 0; i--) {
                            f.removeChild(childs[i]);
                        }

                        $html = '';

                        $.each(data.advice,function(i,val){
                            $html+='<div class="row col-md-9">';
                            $color = "green";
                            $imgSrc = "/Image/doctor.jpg";
                            if(val.adviser == '系统管理员'){
                                $color='#c700ff';
                                $imgSrc = "/Image/admin.jpg";
                            }
                            $html+='<p style="color:'+$color+'" >';
                            $html+='<img src="'+$imgSrc+'" style="width: 10%">';
                            $html+=val.adviser+':   '+val.content+'</p>';
                            $html+='<hr /> </div>';
                        });

                        f.innerHTML=$html;
                },
                error: function (xhr, type) {
                    alert('Ajax error!');
                }
            });
        });
    });
</script>